<template>
  <div class="goods-tabs">
    <nav>
      <a
        :class="{ active: currContent === 'Detail' }"
        @click="changeTabs('Detail')"
        href="javascript:;"
        >商品详情</a
      >
      <a
        :class="{ active: currContent === 'Comment' }"
        @click="changeTabs('Comment')"
        href="javascript:;"
        >商品评价<span>600+</span></a
      >
    </nav>

    <!--
        动态切换组件 is 注册名字
        这个位置显示注册的对应组件 Detail 或者 Comment

        is还可以解决html元素内部严格限制问题
    -->
    <!--
        keep-alive 组件名字
        组件缓存，来回切换只创建一次

        include="组件名字,组件名字"，只缓存include里的组件
     -->
    <keep-alive>
      <component :is="currContent"></component>
    </keep-alive>

    <!-- <GoodsDetail></GoodsDetail>
    <GoodsComment></GoodsComment> -->
  </div>
</template>
<script>
import { ref } from 'vue'
import Detail from './GoodsDetail'
import Comment from './GoodsComment'
export default {
  name: 'GoodsTabs',

  components: {
    Detail,
    Comment
  },

  setup () {
    // 切换高亮，轮播图，思路：引入一个标识

    // 切换tab时引入比较的currContent不用索引，用'Detail','Comment'
    // 因为后期组件切换时也要用到

    const currContent = ref('Comment')
    const changeTabs = (curr) => {
      currContent.value = curr
    }

    return { changeTabs, currContent }
  }
}
</script>
<style scoped lang="less">
.goods-tabs {
  min-height: 600px;
  background: #fff;
  nav {
    height: 70px;
    line-height: 70px;
    display: flex;
    border-bottom: 1px solid #f5f5f5;
    a {
      padding: 0 40px;
      font-size: 18px;
      position: relative;
      > span {
        color: @priceColor;
        font-size: 16px;
        margin-left: 10px;
      }
      &:first-child {
        border-right: 1px solid #f5f5f5;
      }

      // 选中以后的类名
      &.active {
        &::before {
          content: "";
          position: absolute;
          left: 40px;
          bottom: -1px;
          width: 72px;
          height: 2px;
          background: @xtxColor;
        }
      }
    }
  }
}
</style>
